#include "delge_squirrelgame.h"

void MyGame::Startup()
{
	SquirrelObject root = SquirrelVM::GetRootTable(); 
	SquirrelObject s_Startup;

	try
	{
		s_Startup = root.GetValue("Startup");
		SquirrelVM::BeginCall(s_Startup);
		SquirrelVM::EndCall();
		root.Reset();
		s_Startup.Reset();
	}
	catch (SquirrelError& error)
	{
		cout << error.desc << endl;
		this->bIsRunning = false;
		return;
	}
}

void MyGame::Shutdown()
{
	SquirrelObject root = SquirrelVM::GetRootTable(); 
	SquirrelObject s_Shutdown;

	try
	{
		s_Shutdown = root.GetValue("Shutdown");
		SquirrelVM::BeginCall(s_Shutdown);
		SquirrelVM::EndCall();
		root.Reset();
		s_Shutdown.Reset();
	}
	catch (SquirrelError& error)
	{
		cout << error.desc << endl;
		this->bIsRunning = false;
		return;
	}
}

void MyGame::Update(float fDelta)
{
	SquirrelObject root = SquirrelVM::GetRootTable(); 
	SquirrelObject s_Update;

	try
	{
		s_Update = root.GetValue("Update");
		SquirrelVM::BeginCall(s_Update);
		SquirrelVM::PushParam(fDelta);
		SquirrelVM::EndCall();
		root.Reset();
		s_Update.Reset();
	}
	catch (SquirrelError& error)
	{
		cout << error.desc << endl;
		this->bIsRunning = false;
		return;
	}
}

void MyGame::Render()
{
	SquirrelObject root = SquirrelVM::GetRootTable(); 
	SquirrelObject s_Render;

	try
	{
		s_Render = root.GetValue("Render");
		SquirrelVM::BeginCall(s_Render);
		SquirrelVM::EndCall();
		root.Reset();
		s_Render.Reset();
	}
	catch (SquirrelError& error)
	{
		cout << error.desc << endl;
		this->bIsRunning = false;
		return;
	}
}